package ssq.gamest.game.ai;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;

import ssq.gamest.game.Color;
import ssq.gamest.game.Poker;
import ssq.gamest.game.PokerCard;
import ssq.gamest.game.PokerCardGroup;
import ssq.gamest.game.PokerOrderSettings;
import ssq.gamest.game.PokerPattern;
import ssq.gamest.game.Doudizhu.ai.DoudizhuAI;
import ssq.gamest.game.Doudizhu.patterns.单顺;
import ssq.gamest.game.Guandan.ai.GuandanAI;
import ssq.utils.Pair;

public class AITest
{
    @SuppressWarnings("unchecked")
    @Test
    public void testBigger()
    {
        Poker poker = new Poker("斗地主", "Doudizhu");
        
        PokerOrderSettings settings = new PokerOrderSettings(
                Arrays.asList(3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 14, 15), poker);
        settings.setTwoEndian(Arrays.asList(1, 2));
        
        settings.setPatternAndOrder(Arrays.asList(Arrays.asList("`others`", "炸弹", "王炸"),
                Arrays.asList("对子"),
                Arrays.asList("单张"),
                Arrays.asList("三张"),
                Arrays.asList("三带对"),
                Arrays.asList("三带一"),
                Arrays.asList("四带二"),
                Arrays.asList("四带两对"),
                Arrays.asList("单顺"),
                Arrays.asList("双顺"),
                Arrays.asList("三顺"),
                Arrays.asList("单翅膀飞机"),
                Arrays.asList("双翅膀飞机"),
                Arrays.asList("炸弹"),
                Arrays.asList("王炸")
                ));
        
        poker.settings = settings;
        
        DoudizhuAI ai = new DoudizhuAI(new PokerAiSettings(poker));
        
        PokerCardGroup tmpGroup = new PokerCardGroup(
                poker,
                new PokerCard(2, Color.spades, poker),
                new PokerCard(2, Color.spades, poker),
                new PokerCard(3, Color.spades, poker),
                new PokerCard(3, Color.spades, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.hearts, poker),

                new PokerCard(4, Color.spades, poker),
                new PokerCard(6, Color.diamonds, poker),
                new PokerCard(7, Color.diamonds, poker),
                new PokerCard(8, Color.diamonds, poker),
                new PokerCard(9, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker)
                );
        List<Pair<PokerPattern, PokerCardGroup>> result = ai.containsBigger(tmpGroup, new 单顺(poker, 5, 5, Arrays.asList(3)));
        System.out.println(result);
    }
    
    @SuppressWarnings("unchecked")
    @Test
    public void testGuandan()
    {
        Poker poker = new Poker("掼蛋", "Guandan");
        
        PokerOrderSettings settings = new PokerOrderSettings(
                Arrays.asList(2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 1, 10, 14, 15), poker);
        settings.setTwoEndian(Arrays.asList(1));
        
        settings.setPatternAndOrder(Arrays.asList(Arrays.asList("`others`", "炸弹4", "炸弹5", "同花顺", "炸弹6", "王炸"),
                Arrays.asList("对子"),
                Arrays.asList("单张"),
                Arrays.asList("三张"),
                Arrays.asList("三带对"),
                Arrays.asList("顺子"),
                Arrays.asList("连对"),
                Arrays.asList("三顺")));
        
        poker.settings = settings;
        
        GuandanAI ai = new GuandanAI(new PokerAiSettings(poker));
        
        PokerCardGroup tmpGroup = new PokerCardGroup(
                poker,
                new PokerCard(2, Color.spades, poker),
                new PokerCard(2, Color.spades, poker),
                new PokerCard(3, Color.spades, poker),
                new PokerCard(3, Color.spades, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.hearts, poker),
                new PokerCard(6, Color.diamonds, poker),
                new PokerCard(7, Color.diamonds, poker),
                new PokerCard(8, Color.diamonds, poker),
                new PokerCard(9, Color.diamonds, poker),
                new PokerCard(11, Color.diamonds, poker),
                new PokerCard(14, Color.none, poker),
                new PokerCard(15, Color.none, poker),
                new PokerCard(15, Color.none, poker),
                new PokerCard(15, Color.none, poker),
                new PokerCard(2, Color.spades, poker),
                new PokerCard(15, Color.none, poker),
                new PokerCard(15, Color.none, poker),
                new PokerCard(14, Color.none, poker),
                new PokerCard(15, Color.none, poker),
                
                new PokerCard(2, Color.spades, poker),
                new PokerCard(2, Color.spades, poker),
                new PokerCard(3, Color.spades, poker),
                new PokerCard(3, Color.spades, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.hearts, poker),
                //
                new PokerCard(6, Color.diamonds, poker),
                new PokerCard(7, Color.diamonds, poker),
                new PokerCard(8, Color.diamonds, poker),
                new PokerCard(9, Color.diamonds, poker),
                new PokerCard(11, Color.diamonds, poker),
                new PokerCard(10, Color.diamonds, poker),
                new PokerCard(14, Color.none, poker),
                new PokerCard(14, Color.none, poker),
                new PokerCard(15, Color.none, poker),
                new PokerCard(15, Color.none, poker)
                //                new PokerCard(15, Color.none, poker),
                //                new PokerCard(2, Color.spades, poker),
                //                new PokerCard(15, Color.none, poker),
                //                new PokerCard(15, Color.none, poker),
                //                new PokerCard(15, Color.none, poker)
                );

        Pair<Double, List<Pair<PokerPattern, PokerCardGroup>>> tmp = ai.divideByPattern(tmpGroup);
        System.out.println(tmp);
    }
    
    @SuppressWarnings("unchecked")
    @Test
    public void testDoudizhu()
    {
        Poker poker = new Poker("斗地主", "Doudizhu");
        
        PokerOrderSettings settings = new PokerOrderSettings(
                Arrays.asList(3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 14, 15), poker);
        settings.setTwoEndian(Arrays.asList(1, 2));
        
        settings.setPatternAndOrder(Arrays.asList(Arrays.asList("`others`", "炸弹", "王炸"),
                Arrays.asList("对子"),
                Arrays.asList("单张"),
                Arrays.asList("三张"),
                Arrays.asList("三带对"),
                Arrays.asList("三带一"),
                Arrays.asList("四带二"),
                Arrays.asList("四带两对"),
                Arrays.asList("单顺"),
                Arrays.asList("双顺"),
                Arrays.asList("三顺"),
                Arrays.asList("单翅膀飞机"),
                Arrays.asList("双翅膀飞机"),
                Arrays.asList("炸弹"),
                Arrays.asList("王炸")
                ));
        
        poker.settings = settings;
        
        DoudizhuAI ai = new DoudizhuAI(new PokerAiSettings(poker));
        
        PokerCardGroup tmpGroup = new PokerCardGroup(
                poker,
                new PokerCard(2, Color.spades, poker),
                new PokerCard(2, Color.spades, poker),
                new PokerCard(3, Color.spades, poker),
                new PokerCard(3, Color.spades, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.hearts, poker),

                new PokerCard(4, Color.spades, poker),
                new PokerCard(6, Color.diamonds, poker),
                new PokerCard(7, Color.diamonds, poker),
                new PokerCard(8, Color.diamonds, poker),
                new PokerCard(9, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),

                new PokerCard(4, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),
                new PokerCard(4, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),
                new PokerCard(2, Color.spades, poker),
                new PokerCard(2, Color.spades, poker),
                new PokerCard(3, Color.spades, poker),
                new PokerCard(3, Color.spades, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),

                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.diamonds, poker),
                new PokerCard(3, Color.hearts, poker),
                new PokerCard(6, Color.diamonds, poker),
                new PokerCard(7, Color.diamonds, poker),
                new PokerCard(8, Color.diamonds, poker),
                new PokerCard(9, Color.diamonds, poker),
                new PokerCard(11, Color.diamonds, poker),
                new PokerCard(10, Color.diamonds, poker),

                new PokerCard(14, Color.none, poker),
                new PokerCard(5, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),
                new PokerCard(2, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),
                new PokerCard(5, Color.diamonds, poker),
                
                new PokerCard(15, Color.none, poker)
                );
        
        Pair<Double, List<Pair<PokerPattern, PokerCardGroup>>> tmp = ai.divideByPattern(tmpGroup);
        System.out.println(tmp);
    }
}
